import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

import { Subject } from 'rxjs';
import { Observable } from 'rxjs';
import { map } from "rxjs/operators";
@Injectable()
export class SystemInfoService {
    /**用于在路由的环境下与父组件通讯 */
    private routeMsgPushSource = new Subject<string>();
    routeMsgPush$ = this.routeMsgPushSource.asObservable();

    constructor(private http: HttpClient) { }

    /** 获取系统树状结构 */
    getSystemTree() {
        return this.http.get('/system/api/info/listtree').pipe(
            map((res:Response) => res['data'])
        )
    }
    /**保存或更新系统信息 */
    saveUpdateSysInfo(sysInfo: any) {
        return this.http.post('/system/api/info/saveupdate', sysInfo).pipe(
            map((res:Response) => res['data'])
        )
    }
    /** 获取指定系统详情 */
    getSysInfoDetail(id: number) {
        return this.http.get('/system/api/info/load?id=' + id).pipe(
            map((res:Response) => res['data'])
        )
    }
    /** 删除子系统 */
    deleteSystem(id: number) {
        return this.http.get('/system/info/delete?id=' + id).pipe(
            map((res:Response) => res['data'])
        )
    }
    /**父子组件通讯 */
    announceMission(id: string) {
        this.routeMsgPushSource.next(id);
    }
    /**更新basis数据*/
    basisUpdate() {
        return this.http.post('/system/api/unitinfo/getDynamicUnitInfo',true).pipe(
            map((res:Response) => res['data'])
        )
    }
}
